 <?php if($_SESSION['Permit']==1)
 { 
   
	$sql =sprintf("select * from tblmenu ");
	if(isset($_POST['type']))
	{ 
	  if($_POST['type']==0)
	  $sid="='0'";
	  else
	 if($_POST['type']==-1)
	 $sid="='-1' order by parent_id";
	 else
	 $sid=">'0' order by parent_id";
	$sql =sprintf("select * from tblmenu where section_id%s",$sid);
	}
 } 
 else
 { 
 	if(isset($_POST['type']) && $_POST['type'] ==1){
 		$sql =sprintf("SELECT * FROM tblmenu where section_id in(%s) union SELECT * FROM tblmenu where parent_id in(SELECT id FROM tblmenu where section_id in(%s))",$_SESSION['ArraySec'],$_SESSION['ArraySec']);
	}else{


		$sql =sprintf("SELECT * FROM tblmenu where parent_id in(SELECT id FROM tblmenu where section_id in(%s))",$_SESSION['ArraySec']);
	}

 }   

   $kq=mysql_query($sql)or die(mysql_error()); 
?>
  <script type="text/javascript">
  
  function Delete()
  {	  
  		var answer = confirm ("Bạn có chắc là muốn xóa những mục đã chọn?");
		if (answer)
		{
			document.mylist.submit();
		}
  }

  function checkAll(control)
	{
		field= document.getElementsByName('cid[]');
		if(control.checked)
{ 
		for (i = 0; i < field.length; i++)
		field[i].checked = true ;
	}

else

for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}




 </script>    
   

   <div align="center" style="padding:10 10 10 10; border:1px black solid;">
    
  <table>
  	<tr>
    	<td colspan="4"><h3>Quản lý Menu</h3></td>
        <td colspan="2" align="right">
        	<a  href="menua" title="Thêm mới một menu" style="margin-right:15px;"><img src="img/Add.png" width="32" height="32" border="none"/></a>
        	<a  style="margin-right:15px;" title="Xóa mục đã chọn" onclick="Delete()"><img src="img/delete.png" width="32" height="32"/></a>
		   	
        </td>
    </tr>
    <tr>
    	<td colspan="6">
        	<form name="formEdit" action="" method="POST">
      			<label for="type">
                	<strong>Chọn kiểu menu</strong>
                </label>
      				
      			<select name="type" id="type" onchange="submit()">
      				<?php if($_SESSION['Permit']==1) echo "<option value='0'>menu</option>";?>
                    <option value="1" <?php if(isset($_POST['type'])&&$_POST['type']==1)echo"selected='selected'" ?>  >section</option>
                    <option value="-1" <?php if(isset($_POST['type'])&&$_POST['type']==-1)echo"selected='selected'" ?>>article</option>
      			</select>
    		</form>
   		</td> 
    </tr>
    
  
    <tr bgcolor="#008000" style="color:white; height:30px;">
       <th width="22" ><input type="checkbox" name="toggle"  id="toggle" onclick=" checkAll(this);" /></th>
      <th width="140" >Tên Tiếng Việt</th>
      <th width="140" >Tên Tiếng Anh</th>
      <th width="310" >URL  </th>
       <th width="310" > Type  </th>
      <th width="47" >Vị trí</th>
       
    </tr>
   <form name="mylist" action="Menu/deletemenu.php" method="post"> 
    <?php  $i=0;
	while($row=mysql_fetch_assoc($kq))
	{
		$i++;
	?>
     <tr  bgcolor="<?php if($i%2!=0) echo '#f6f8db';else echo  '#9ff1a1'?>" onmouseover="changeback(this);" onmouseout="changebre(this);">
    	  <td align="center"><input type="checkbox" name="cid[]" value="<?php echo $row['id']?>" /></td>
         <td ><a href="menue&id=<?php echo $row['id']?>"><?php echo $row['vi_name'];?></a></td>
         <td ><a href="menue&id=<?php echo $row['id']?>"><?php echo $row['en_name'];?></a></td>
         <td ><?php echo $row['URL']; ?></td>
          <td ><?php if($row['section_id']>0) echo "section";else if($row['section_id']==0)echo "menu" ;else echo "article";  ?></td>
    	 <td ><?php echo $row['order']; ?></td>
	
    <?php
	}
	?>
 
      </form> 
   </table>
</div>
